package com.sixkey.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sixkey.constant.CommonConstant;
import com.sixkey.entity.Evaluation;
import com.sixkey.entity.Feedback;
import com.sixkey.entity.User;
import com.sixkey.entity.vo.FeedbackVo;
import com.sixkey.mapper.FeedbackMapper;
import com.sixkey.service.IFeedbackService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sixkey.service.IUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

import static com.sixkey.constant.CommonConstant.*;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2023-10-18
 */
@Service
@RequiredArgsConstructor
public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback> implements IFeedbackService {

    private final IUserService userService;

    /**
     * 小程序端用户反馈数据展示
     * @param
     * @return
     */
    @Override
    public List<Feedback> getFeedbackList() {
        QueryWrapper<Feedback> wrapper = new QueryWrapper<>();
        wrapper.eq("status", FEED_BACK_REPLY_STATUS);
        List<Feedback> feedbackList = this.list(wrapper);
        return feedbackList;
    }

    /**
     * 后台用户反馈分页查询
     * @param pageNo
     * @param pageSize
     * @param feedbackVo
     * @return
     */
    @Override
    public Page<Feedback> queryList(Integer pageNo, Integer pageSize, FeedbackVo feedbackVo) {
        Page<Feedback> pageInfo = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<Feedback> wrapper = new LambdaQueryWrapper<>();
        //添加过滤条件(模糊查询)
        wrapper.like(!StringUtils.isEmpty(feedbackVo.getPhone()),Feedback::getPhone,feedbackVo.getPhone());
        wrapper.like(!StringUtils.isEmpty(feedbackVo.getStatus()),Feedback::getStatus,feedbackVo.getStatus());
        //添加排序条件
        wrapper.orderByDesc(Feedback::getUpdateTime);
        Page<Feedback> feedbackPage = this.page(pageInfo, wrapper);
        return feedbackPage;
    }
}
